package com.picturehistory.core.rest.dao;

import org.springframework.orm.jdo.support.JdoDaoSupport;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.picturehistory.core.rest.model.Location;

public class LocationDAOJDOImpl extends JdoDaoSupport implements LocationDAO {

	@Override
	public Location loadByLatLng(Double lat, Double lng) {
		Key key = KeyFactory.createKey(Location.class.getName(), lat+","+lng);
		Location loc = (Location) getJdoTemplate().getObjectById(Location.class, key);
		return loc;
	}

	@Override
	public Location store(Double lat, Double lng) {
		// 
		Location loc = new Location(lat, lng);
		Key key = KeyFactory.createKey(Location.class.getName(), lat+","+lng);
		loc.setKey(key);
		
		getJdoTemplate().makePersistent(loc);
		return loc;
	}

}
